package com.arvin.faceDetect.db

import androidx.room.*
import kotlinx.coroutines.flow.Flow

@Dao
interface FaceDao {
    @Query("SELECT * FROM faces ORDER BY createTime DESC")
    fun getAllFaces(): Flow<List<FaceEntity>>

    @Query("SELECT * FROM faces ORDER BY createTime DESC")
    suspend fun getAllFacesList(): List<FaceEntity>

    @Query("SELECT * FROM faces ORDER BY createTime DESC LIMIT 1")
    suspend fun getLastCollectedFace(): FaceEntity?

    @Query("SELECT * FROM faces WHERE name LIKE :query ORDER BY createTime DESC")
    suspend fun searchFaces(query: String): List<FaceEntity>

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insertFace(face: FaceEntity)

    @Update
    suspend fun updateFace(face: FaceEntity)

    @Delete
    suspend fun deleteFace(face: FaceEntity)

    @Delete
    suspend fun deleteFaces(faces: List<FaceEntity>)

    @Query("SELECT * FROM faces WHERE id = :id")
    suspend fun getFaceById(id: String): FaceEntity?

    @Query("SELECT * FROM faces WHERE id IN (:ids)")
    suspend fun getFacesByIds(ids: List<String>): List<FaceEntity>

    @Query("DELETE FROM faces")
    suspend fun deleteAllFaces()

    @Query("SELECT * FROM faces")
    suspend fun getAllFacesForComparison(): List<FaceEntity>
} 